package com.beiding.test.pg;

import com.beiding.sqlbuilder.ConditionUnit;
import com.beiding.sqlbuilder.ConditionUnitHandler;
import com.beiding.sqlbuilder.OperationConnector;

public class OperationConnectorHandler implements ConditionUnitHandler {
    @Override
    public boolean canHandle(ConditionUnit conditionUnit) {
        return conditionUnit instanceof OperationConnector;
    }

    @Override
    public String handle(ConditionUnit conditionUnit) {
        OperationConnector operationConnector = (OperationConnector) conditionUnit;
        switch (operationConnector.getOperationType()) {
            case Plus:
                return symbol("+");
            case Gt:
                return symbol(">");
            case Lt:
                return symbol("<");
        }
        throw new RuntimeException("不支持操作:" + operationConnector.getOperationType());
    }

    private String symbol(String s) {
        return " " + s + " ";
    }

}
